package control;

import dao.DiaryDao;
import entity.DiaryInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet("/diary/save")
public class Save extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        Integer id=Integer.valueOf(req.getParameter("id"));
        String contents=req.getParameter("contents");
        DiaryDao dd=new DiaryDao();
        DiaryInfo di=dd.findById(id);
        di.setContents(contents);
        di.setReportTime(new Date());
        dd.update(di);
        resp.sendRedirect("diaryList");
    }
}
